package A2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class URL2 {
    static String url = "https://www.baidu.com/";
    public static void main(String[] args) {
        HttpURLConnection get1 = null;
        BufferedReader br = null;
        try {
            URL get = new URL(url);
            get1 = (HttpURLConnection) get.openConnection();
            get1.setRequestMethod("GET");
            InputStreamReader in = new InputStreamReader(get1.getInputStream());
            br = new BufferedReader(in);
            StringBuilder app = new StringBuilder();
            String str = br.readLine();
            System.out.println(str);
            while (str!=null){
                app.append(str);
                app.append("\n");
                str= br.readLine();
            }
            System.out.println(app);

        }catch (Throwable e ){
            e.printStackTrace();

        }finally {
            if (get1 != null){
                get1.disconnect();
            }if(br != null ){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
